from fastapi import FastAPI
from models import get_category
from typing import List, Optional

from fastapi.staticfiles import StaticFiles
from pathlib import Path

from fastapi.middleware.cors import CORSMiddleware

# app对象
app = FastAPI()
origins = [
    "http://localhost:5173",  # Vue 运行的端口默认是5173
    "http://127.0.0.1:5173",
]

app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)


@app.get("/")
def index():
    return {"code": "hello, fastAPI"}


@app.get("/home/category/head")
def read_root():
    return {"code": "1", "msg": "操作成功", "result": get_category()}


if __name__ == "__main__":
    import uvicorn

    uvicorn.run(app, host="127.0.0.1", port=8000)
